// Vue
import Vue from 'vue';
import App from './App';
import 'flex.css';
import './common';
import themeVarJson from '@/config/themeVars.json';
// store
import store from '@/store/index';
import 'ie-placeholder'; //ie兼容placeholder
import '@/style/index.scss';
import '@babel/polyfill';
require('es6-promise').polyfill();
require('es6-promise/auto');
// 菜单和路由设置
import router from './router';
import { frameInRoutes } from '@/router/routes';
import instructions from '@/common/instructions';
Vue.use(instructions);

import VueLazyLoad from 'vue-lazyload';
Vue.use(VueLazyLoad);
import browerVersion from './utils/browerVersion';
Vue.prototype.$isIE9 = browerVersion();
window.themeVars = themeVarJson;
new Vue({
  router,
  store,
  render: (h) => h(App),
  created() {
    // 处理路由 得到每一级的路由设置
    this.$store.commit('vxadmin/page/init', frameInRoutes);
    // change by lss
    this.$store.dispatch('vxadmin/menu/loadMenu').then((menu) => {
      if (menu) {
        // 设置顶栏菜单
        this.$store.commit('vxadmin/menu/headerSet', menu);
        // 初始化菜单搜索功能
        this.$store.commit('vxadmin/search/init', menu);
      }
    });
  },
  mounted() {
    // 展示系统信息
    this.$store.commit('vxadmin/releases/versionShow');
    // 用户登录后从数据库加载一系列的设置
    this.$store.dispatch('vxadmin/account/load');
  },
  watch: {
    // // 检测路由变化切换侧边栏内容
    // '$route.matched': {
    //   handler(matched) {
    //     if (matched.length > 0) {
    //       // change by lss
    //       const menuAside = this.$store.state.vxadmin.menu.header;
    //       let path = matched[0].path;
    //       // 如果是过渡页面则不刷新侧边栏 add by lss
    //       if (matched[matched.length - 1].path === '/blank') {
    //         return false;
    //       }
    //       const _side = menuAside.filter((menu) => menu.path === path);
    //       if (_side.length > 0) {
    //         sessionStorage.setItem('menuSide', JSON.stringify(_side[0]));
    //       }
    //       this.$store.commit('vxadmin/menu/asideSet', _side.length > 0 ? _side[0].children : []);
    //       this.$store.commit('vxadmin/menu/asideTitleSet', _side.length > 0 ? _side[0].title : '');
    //     }
    //   },
    //   immediate: true,
    // },
  },
}).$mount('#app');
